# Contributor: Jeff Bilyk <jbilyk@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=rtpproxy
pkgver=2.1.1
pkgrel=0
pkgdesc="RTP proxy"
url="https://www.rtpproxy.org/"
arch="all"
license="BSD-2-CLause"
makedepends="libsndfile-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-debug $pkgname-tools $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/sippy/rtpproxy/archive/v$pkgver.tar.gz
	DEFFILEMODE.patch
	musl-fix-headers.patch
	define-byte-order.patch
	prevent-pthread-from-running-macro.patch
	rtpproxy.confd
	rtpproxy.initd"

prepare() {
	default_prepare
	update_config_sub
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info
	make
}

debug() {
	pkgdesc="Debug version of rtpproxy"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/${pkgname}_debug "$subpkgdir"/usr/bin/
}

tools() {
	pkgdesc="User tools for $pkgname"
	mkdir -p "$subpkgdir"/usr/bin
	for _a in extractaudio makeann; do
		mv "$pkgdir"/usr/bin/$_a "$subpkgdir"/usr/bin/
	done
}

package() {
	make DESTDIR="$pkgdir" install
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="f8e520117671e8b46e5e99845efb6eca76d0861d6edae8dcd445dffb970a572e5eeb6e88ba5c9af0603b30dcf197feecb470716c3e32cfff5120ad21420556bd  rtpproxy-2.1.1.tar.gz
9191c99c98e7576381f6da3fce44c8470b8cad150e8c23c22332caef5b7db81561694390934548cf855b45be895517d370d66cbec39565285f66e0e04c66ee1e  DEFFILEMODE.patch
bd05f24bfa66cd9491135efe341359cc4b16b80fd9c45fbfc880c7a82ba53ad5f2317dd6bfbaecfd0dd42ba0d54a55041403ba6409b8deff568fcb095892956d  musl-fix-headers.patch
8ab21c20ee87c0d9ef9a113b436eaecd34d93c596d761b2f4b8d746c34946acb41421ab24be6446dd2ad2c0c3e1cd894637d945e945a90e1af1eda091d91306f  define-byte-order.patch
ba54855fd147c8f166939b37a18c0576c55481c762c3f5b9e0ffa45e00eedeeaabb1d3fd4e45fe8f59f43064ecd852d87f83bcc8f746923219e9e3a795cf592e  prevent-pthread-from-running-macro.patch
e2ab3705329ffd10a8a5723ac3a07a2f98547f29b7055e1616ebbd141d6beff9c81d44579af9f3486f7835a7ac7228ecfe49cf09208438ed490843c6b100a104  rtpproxy.confd
84f05c765369aa5ef747361e57c557b2560ac734225f5aad99ba28f4178a73d2c937a316fa45f0d42cab27b1c9d033019d98ec67601f0b272b9b45c9196bf2fb  rtpproxy.initd"
